Fk:loadTranslationTable{
  ["plum__yuzhi"] = "鱼炙",
  [":plum__yuzhi"] = "轮次开始时，你可以令任意名角色选择是否令你摸一张牌，然后你交给选择“是”的其他角色各一张牌。" ..
  "你以此法交出的牌不计入手牌上限，且于获得的首轮被使用时，使用者受到1点火焰伤害令之不可响应；" ..
  "过一轮后，可以当【酒】使用；再过一轮后，只能用于重铸。",

  ["#plum__yuzhi-ivk"] = "鱼炙：可以令任意名角色选择是否令你摸一张牌",
  ["#plum__yuzhi-draw"] = "鱼炙：可以令%src摸一张牌",
  ["#plum__yuzhi-yiji"] = "鱼炙：交给选择“是”的其他角色各一张牌",

  ["@plum__yuzhi-inhand"] = "鱼炙",
  ["#plum__yuzhi-heat"] = "火",
  ["#plum__yuzhi-smelly"] = "酒",
  ["#plum__rotted"] = "重铸",
}

local mark_tab = { "#plum__yuzhi-heat", "#plum__yuzhi-smelly", "#plum__rotted" }
local translate_mark_tab = table.map(mark_tab, function (e) return Fk:translate(e) end)

local yuzhi = fk.CreateSkill{
  name = "plum__yuzhi",
}

yuzhi:addAcquireEffect(function (self, player, is_start)
  for _, p in ipairs(player.room:getAlivePlayers(true)) do
    player.room:handleAddLoseSkills(p, "plum__yuzhi_analeptic|plum__yuzhi_recast")
  end
end)

yuzhi:addLoseEffect(function (self, player, is_death)
  for _, p in ipairs(player.room:getAlivePlayers(true)) do
    player.room:handleAddLoseSkills(p, "-plum__yuzhi_analeptic|-plum__yuzhi_recast")
  end
end)

--- exclude judge
---@param card Card
---@return boolean
local exclude = function(card)
  if card:getMark("@plum__yuzhi-inhand") ~= 0 then
    return true
  end
  return false
end

--- handcard max
yuzhi:addEffect("maxcards", {
  exclude_from = function(self, player, card)
    if exclude(card) then
      return true
    end
  end,
})

--- prohibit use
yuzhi:addEffect("prohibit", {
  prohibit_use = function (self, player, card)
    if card:getMark("@plum__yuzhi-inhand") == translate_mark_tab[3] then
      return true
    end
  end
})

--- heat refresh
yuzhi:addEffect(fk.PreCardUse, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(yuzhi.name) and data.card:getMark("@plum__yuzhi-inhand") == Fk:translate(mark_tab[1])
  end,
  on_refresh = function (self, event, target, player, data)
    data.extra_data = data.extra_data or {}
    data.extra_data.plum__yuzhi = true
  end
})

--- refresh
yuzhi:addEffect(fk.RoundEnd, {
  can_refresh = function (self, event, target, player, data)
    return player:getHandcardNum() > 0
  end,
  on_refresh = function (self, event, target, player, data)
    for _, id in ipairs(player:getCardIds(Player.Hand)) do
      local card = Fk:getCardById(id)
      local mark = card:getMark("@plum__yuzhi-inhand")
      local i = table.indexOf(translate_mark_tab, mark)
      if i > 0 then
        i = math.min(3, i + 1)
        mark = mark_tab[i]
      end
      player.room:setCardMark(card, "@plum__yuzhi-inhand", Fk:translate(mark))
    end
  end
})

--- main
yuzhi:addEffect(fk.RoundStart, {
  anim_type = "support",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(yuzhi.name)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      targets = room:getAlivePlayers(false),
      min_num = 1,
      max_num = 999,
      cancelable = true,
      skill_name = yuzhi.name,
      prompt = "#plum__yuzhi-ivk"
    })
    if #tos == 0 then return end
    event:setCostData(self, { tos = tos })
    return true
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self).tos ---@type ServerPlayer[]
    local attitude_tab = {}
    for _, p in ipairs(tos) do
      if player.dead or p.dead then break end
      local ret = room:askToSkillInvoke(p, {
        skill_name = yuzhi.name,
        prompt = "#plum__yuzhi-draw:" .. player.id
      })
      attitude_tab[p.id] = ret
      if ret then
        player:drawCards(1, yuzhi.name)
      end
    end
    if player.dead then return end
    local able_targets = table.filter(room:getOtherPlayers(player, false), function (p) return attitude_tab[p.id] end)
    room:askToYiji(player, {
      min_num = #able_targets,
      max_num = #able_targets,
      skill_name = yuzhi.name,
      cancelable = false,
      moveMark = {"@plum__yuzhi-inhand", Fk:translate("#plum__yuzhi-heat")},
      prompt = "#plum__yuzhi-yiji",
      single_max = 1,
      targets = able_targets
    })
  end
})

--- heat
yuzhi:addEffect(fk.CardUsing, {
  anim_type = "negative",
  can_trigger = function (self, event, target, player, data)
    return player == target and data.extra_data and data.extra_data.plum__yuzhi
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    data.disresponsiveList = room.alive_players
    room:damage{
      to = player,
      damage = 1,
      damageType = fk.FireDamage,
      from = player,
      skillName = yuzhi.name
    }
  end
})

return yuzhi